//
//  StatusCell.swift
//  微博项目
//
//  Created by zhaoyinpeng on 16/3/15.
//  Copyright © 2016年 zhaoyinpeng. All rights reserved.
//

import UIKit

class StatusCell: UITableViewCell {

    
    //.模型数据
    var status: Status? {
        didSet {
            
            //.绑定模型数据
            originalView.status = status
            
            //.如果是转发微博的话  就给转发微博数据模型赋值
            if let re = status?.retweeted_status {
                retweetedView.retweetedStatus = re
            }
        }
    }
    
   
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        //.设置选中状态
        self.selectionStyle = .None
         setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
    //.MARK: 设置UI
    private func setupUI() {
        //.添加子视图
//        backgroundColor = UIColor.blueColor()
        contentView.addSubview(originalView)
        contentView.addSubview(bottomView)
        contentView.addSubview(retweetedView)
        
        
        
        //.设置约束
        originalView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentView.snp_top)
            make.left.equalTo(contentView.snp_left)
            make.right.equalTo(contentView.snp_right)
//            make.height.equalTo(100)
        }
        
        retweetedView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(originalView.snp_bottom)
            make.left.right.equalTo(originalView)
        }
        
        bottomView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(contentView.snp_left)
            make.right.equalTo(contentView.snp_right)
            make.top.equalTo(retweetedView.snp_bottom)
            make.height.equalTo(36)
        }
        
        //.开启自动布局之后，所有的frame布局就会自动失效
        contentView.snp_makeConstraints { (make) -> Void in
            make.left.right.top.equalTo(self)
            make.bottom.equalTo(bottomView.snp_bottom)
        }
    }
   
  
    
    //.原创微博
    private lazy var originalView: StatusOriginalView = StatusOriginalView()
    //.微博底部视图
    private lazy var bottomView: StatusBottomView = StatusBottomView()
    //.转发微博视图
    private lazy var retweetedView: StatusRetweetedView = StatusRetweetedView()
    
    
}
